/**
 * 详情对话框
 */
var LxSpWzhInfoDlg = {
    data: {
        spTxm: "",
        spGuige: "",
        spName: "",
        spDanwei: "",
        spChandi: "",
        spChuo: "",
        spSuoshu: "",
        spLings: "",
        spPifa: "",
        spBz: ""
    }
};

layui.use(['form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    $.ajax({
        url: Feng.ctxPath + "/lxSpWzh/list2",
        dataType: 'json',
        type: 'get',
        success: function (data) {
            console.log(data);//下面会提到这个data是什么值
            //使用循环遍历，给下拉列表赋值
            $.each(data.data, function (index, value) {
                var option = new Option(value.lbName, value.lbid);
                if (value.lbName === $("#spSuoshu").val()) {
                    option.selected = true; // 设置该选项为选中状态
                }
                $('#dp').append(option);
            });
            layui.form.render("select");
        }
    })
    //让当前iframe弹层高度适应
    admin.iframeAuto();

    form.on('select(xmFilter)', function(data){
        var lb = data.value //得到被选中的值
        $("#spSuoshu").val(lb);
    });
    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/lxSpWzh/detail?spId=" + Feng.getUrlParam("spId"));
    var result = ajax.start();
    form.val('lxSpWzhForm', result.data);

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/lxSpWzh/editItem", function (data) {
            Feng.success("更新成功！");
            window.location.href = Feng.ctxPath + '/lxSpWzh'
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/lxSpWzh'
    });

});